<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo{
            background-color: aquamarine;
        }
    </style>
</head>
<body>
    <button id="btn">点我创建一个输入框</button>
    <script>
        const btn=document.getElementById('btn')
        btn.onclick=function()
        {
            const inp=document.createElement('input') 
            inp.className='demo'
            inp.value='戴莹慧'
            
            //inp.focus()  //放在这里不管用 得放在下面

            document.body.appendChild(inp)   //将inp放入页面


            inp.focus()
            inp.parentElement.style.backgroundColor='blue'
        }
    </script>
</body>
</html>